using UnityEngine;

public class PlayerStats : CharacterStats
{
    private Player player;

    protected override void Awake()
    {
        base.Awake();
        player = GetComponent<Player>();
    }

    protected override void Die()
    {
        base.Die();
        player.Die();
        GameManager.Instance.lostCurrencyAmount = PlayerManager.Instance.currency;
        PlayerManager.Instance.currency = 0;
        GetComponent<PlayerItemDrop>()?.GenerateDrop();
    }

    protected override void DecreaseHpBy(int damage, Color color = default)
    {
        base.DecreaseHpBy(damage, color);
        if (damage > GetMaxHp() * 0.3f)
        {
            player.SetupKnockbackPower(10, 6);
            player.Fx.ScreenShake(player.Fx.shakeHighDamage);
            AudioManager.Instance.PlaySfx(34, player.transform);
        }
        ItemDataEquipment currentArmor = player.Inventory.GetEquipment(EquipmentType.Armor);
        currentArmor?.Effect(player.transform, player);
    }

    public override void OnEvasion()
    {
        SkillManager.Instance.Dodge.CreateMirageOnDodge();
    }

    public void CloneDoDamage(CharacterStats targetStats, float multiplier)
    {
        if (TargetCanAvoidAttack(targetStats))
        {
            return;
        }
        int totalDamage = damage.GetValue() + strength.GetValue();
        if (multiplier > 0)
        {
            totalDamage = Mathf.RoundToInt(totalDamage * multiplier);
        }
        if (CanCrit())
        {
            totalDamage = CalculateCriticalDamage(totalDamage);
        }
        totalDamage = CheckTargetArmor(targetStats, totalDamage);
        targetStats.TakeDamage(totalDamage);
        /* if inventory current weapon is magical, then apply magical damage
        or remove if you don't want to apply magic hit on primary attack */
        DoMagicalDamage(targetStats);
    }
}